#ifndef __USER_MODBUS_H
#define __USER_MODBUS_H

#define SW_MAX_NUMBER	11

//实时数据功能地址，使用modbus的0x04指令进行读取
typedef enum
{
	RTD_ADD_VOLTAGE=0X00,  	//电压
	RTD_ADD_LECUR,					//漏电电流
	RTD_ADD_POWER,					//线路功率
	RTD_ADD_TEMP,						//温度
	RTD_ADD_LINECUR,				//线路电流
	RTD_ADD_ALARM,					//报警
	RTD_ADD_ENERGY_L,				//电量低
	RTD_ADD_ENERGY_H,				//电量高
	RTD_ADD_MAX,
}rtdType;


typedef enum
{
	/*如下的七种信息每个开关都对应的有*/
	INFOSUB_ALARM_FLAG=0x00,//报警标志，2byte
	INFOSUB_ENERGY,					//线路电量，4byte
	INFOSUB_VOLTAGE,				//线路电压，4byte
	INFOSUB_LECUR,					//漏电电流，2byte
	INFOSUB_POWER,					//线路功率，2byte
	INFOSUB_TEMP,						//温度，2byte
	INFOSUB_LINECUR,				//线路电流，2byte
	INFOSUB_MAX,						//
}infoSubType;
typedef enum
{	
	INFO_SW_NUM=0x00,				//开关路数，1byte
	INFO_REMCON_FLAG,				//远程控制标志，1-3byte
	INFO_SW_STATE,					//开关状态，1-3byte
	INFO_MAX,
}infoType;


typedef struct
{
	uint8_t validFlag;		//数据是否有效，1bit代表一种，从低位到高位，共7bit
	
	uint16_t alarmFlag;		//报警标志
	uint32_t energy;			//线路电量
	uint16_t voltage;			//线路电压
	uint16_t lecur;				//线路电流
	uint16_t power;				//线路功率
	uint16_t temp;				//温度
	uint16_t lineCur;			//线路电流
}InfoType;

void umb_init(void);
uint8_t umb_setInfo(uint8_t info_type,uint32_t value);
uint8_t umb_setSubInfo(uint8_t sw_num,uint8_t info_type,uint32_t value);
uint32_t umb_getInfo(uint8_t info_type);
uint32_t umb_getSubInfo(uint8_t sw_num,uint8_t info_type);
void umb_setOneSw(uint8_t swnum,uint8_t state);
uint8_t umb_putSendQueue(uint8_t add,uint8_t cmd,uint8_t *data,uint8_t datalen,uint8_t flag);

#endif

